package com.example.a35876.mydemo.ui;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a35876.mydemo.R;
import com.example.a35876.mydemo.bean.ssss;
import com.example.a35876.mydemo.zhifubao.PayDemoActivity;
import com.example.mygaode.ui.MainActivity_ditutu;
import com.example.mylibrarybase.bar.initAction_Bar;
import com.example.mylibrarybase.base.baseui.BaseActivity;
import com.example.mylibrarybase.base.texstListViewAdapter;
import com.example.mylibrarybase.bean.Item_base;
import com.example.mylibrarybase.net.netWork;
import com.example.mylibrarybase.utils.BasicNameValuePair.BasicNameValuePair;
import com.example.mylibrarybase.utils.LogUtils;
import com.example.mylibrarybase.utils.Utils;
import com.example.mylibrarybase.utils.UtilsToast;
import com.example.mylibrarybase.view.MyListView;
import com.example.mylibrarybase.yumengmeng01.ui.activity_01_viewpager;
import com.example.mylibrarybase.yumengmeng02.ui.Activity_MyRecyclerView_02;
import com.example.mylibrarybase.yumengmeng03.ui.Bottom_navigation_bar_Activity_03;
import com.example.mylibrarybase.yumengmeng04.ui.MainActivity_04;
import com.example.mylibrarybase.yumengmeng05.ui.Main2Activity_05;
import com.example.mylibrarybase.yumengmeng06.ui.MainActivity_viewpager_list_06;
import com.example.mylibrarybase.yumengmeng07.ui.MainActivity_list_07;
import com.example.mylibrarybase.yumengmeng08.ui.MainActivity_dialog_08;
import com.example.mylibrarybase.yumengmeng09.ui.MainActivity_loadView_09;
import com.example.mylibrarybase.yumengmeng10.ui.activity_login_10;
import com.example.mylibrarybase.yumengmeng11.ui.MainActivity_popwindow_11;
import com.example.mylibrarybase.yumengmeng12.ui.MainActivity_recyclerview_12;
import com.example.mylibrarybase.yumengmeng13.ui.MainActivity_13_Recyclerviewchebox;
import com.example.mylibrarybase.yumengmeng14.ui.MainActivity_14_animateLayoutChanges;
import com.example.mylibrarybase.yumengmeng15.ui.MainActivity_15_flexible;
import com.example.mylibrarybase.yumengmeng16.ui.MainActivity_16_listmeun;
import com.example.mylibrarybase.yumengmeng18.ui.MainActivity_18_AsyncTask;
import com.example.mylibrarybase.yumengmeng19.ui.MainActivity_19_task_stack;
import com.example.mylibrarybase.yumengmeng20.ui.MainActivity_20_socket;
import com.example.mylibrarybase.yumengmeng21.MainActivity_21_handler;
import com.example.mylibrarybase.yumengmeng24.ui.MainActivity_shijianfenfa_24;
import com.example.mylibrarybase.yumengmeng25.ui.MainActivity_25_jsonjiamijiemi;
import com.example.mylibrarybase.yumengmeng26.ui.MainActivity_26;
import com.example.mylibrarybase.yumengmengtest.MainActivity_test;
import com.lzy.okgo.cache.CacheMode;

import java.util.ArrayList;
import java.util.List;

import static com.example.mylibrarybase.net.netWork.test222;

public class  MainActivity extends BaseActivity {

    private MyListView mBase_activity_listview;
    private texstListViewAdapter mMyListViewAdapter;
    private ArrayList<Item_base> mMItem_bases;
    private initAction_Bar mBase_action_bar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    public void initView() {
        mBase_activity_listview = (MyListView) findViewById(R.id.base_activity_listview);
        mBase_action_bar = (initAction_Bar) findViewById(R.id.base_action_bar);
        mBase_action_bar
                .setMode(initAction_Bar.AUTO_ONCLICK_MODE)
                .setCallBack(new initAction_Bar.Action_bar_call_back() {
            @Override
            public void getAction_barView_backbutton(TextView textView) {
                textView.setText("返回");
            }

            @Override
            public void getAction_barView_backbutton_icon(ImageView imageView) {

            }

            @Override
            public void getAction_barView_title(TextView textView) {
                textView.setText("主标题");
            }

            @Override
            public void getAction_barView_right_icon(ImageView imageView) {

            }
        });
//

        initData();

    }

    @Override
    public void initData() {
        netWork.goPostArray(this, test222, null, "2", CacheMode.NO_CACHE, new netWork.CallBackArray() {

            @Override
            public void onSuccess(String jsonArray) {
//                List<ssss> nextCityList =
//                        JSON.parseArray("NextCityList", ssss.class);
//                LogUtils.i("nextCityList"+nextCityList.toString());
                List<ssss> nextCityList = ssss.arrayssssFromData(jsonArray, "");
                LogUtils.i("nextCityList"+nextCityList.toString());
            }

            @Override
            public void onError(String error) {

            }
        });


        mMItem_bases = new ArrayList<>();
        mMItem_bases.add(new Item_base("0标题"));
        mMItem_bases.add(new Item_base("1自动轮播带指示器"));
        mMItem_bases.add(new Item_base("2选取图片在列表上显示"));
        mMItem_bases.add(new Item_base("3头尾导航栏"));
        mMItem_bases.add(new Item_base("4ListView"));
        mMItem_bases.add(new Item_base("5浏览器"));
        mMItem_bases.add(new Item_base("6ViewPager+frgment+listView+intcor"));
        mMItem_bases.add(new Item_base("7动态列表"));
        mMItem_bases.add(new Item_base("8自定义dialog"));
        mMItem_bases.add(new Item_base("9loadingview"));
        mMItem_bases.add(new Item_base("10倒计时"));
        mMItem_bases.add(new Item_base("11popwindow"));
        mMItem_bases.add(new Item_base("12多条目卡片布局"));
        mMItem_bases.add(new Item_base("13recyclerview+chebox"));
        mMItem_bases.add(new Item_base("14显示隐藏"));
        mMItem_bases.add(new Item_base("15灵活的View"));
        mMItem_bases.add(new Item_base("16左面选择右面详细"));
        mMItem_bases.add(new Item_base("17高德地图"));
        mMItem_bases.add(new Item_base("18AsyncTask"));
        mMItem_bases.add(new Item_base("19任务栈"));
        mMItem_bases.add(new Item_base("20socket"));
        mMItem_bases.add(new Item_base("21Handler"));
        mMItem_bases.add(new Item_base("22Test"));
        mMItem_bases.add(new Item_base("23支付宝 微信支付"));
        mMItem_bases.add(new Item_base("24事件分发"));
        mMItem_bases.add(new Item_base("25json加密返回字符串"));
        mMItem_bases.add(new Item_base("26移动的图片"));


        initAdapter();
    }

    private void initAdapter() {

        mMyListViewAdapter = new texstListViewAdapter(this, mMItem_bases);

        mBase_activity_listview.setAdapter(mMyListViewAdapter);
        initLishner();
    }

    private void initLishner() {
        mBase_activity_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                switch (i){
//                    case 0:
//                        Utils.start_Activity(MainActivity1.this,com.example.mylibrarybase.bar.Activity_00_Title1.class,new BasicNameValuePair("pos","1"));
//                    break;
//                    case 1:
//                       Utils.start_Activity(MainActivity1.this,com.example.yumengmeng01.ui.activity_01_viewpager.class);
//                    break;
//                    case 2:
//                      Utils.start_Activity(MainActivity1.this,com.example.yumengmeng02.ui.Activity_MyRecyclerView_02.class);
//                    break;
//                    case 3:
//                  Utils.start_Activity(MainActivity1.this,com.example.yumengmeng03.ui.Bottom_navigation_bar_Activity_03.class);
//                    break;
//                    case 4:
//                      Utils.start_Activity(MainActivity1.this,com.example.yumengmeng04.ui.MainActivity_04_listsingle.class);
//                    break;
//                    case 5:
//                        Utils.start_Activity(MainActivity1.this,com.example.yumengmeng05.ui.Main2Activity_05.class);
//                    break;
//                    case 6:
//                        Utils.start_Activity(MainActivity1.this,com.example.yumengmeng06.ui.MainActivity_viewpager_list_06.class);
//                    break;
//                    case 7:
//                        Utils.start_Activity(MainActivity1.this,com.example.yumengmeng07.ui.MainActivity_list_07.class);
//                    break;
//                    case 8:
//                        Utils.start_Activity(MainActivity1.this,com.example.yumengmeng08.ui.MainActivity_dialog_08.class);
//                    break;
//                    case 9:
//                        Utils.start_Activity(MainActivity1.this,com.example.yumengmeng09.ui.MainActivity_loadView_09.class);
//                    break;
//                    case 10:
//                        Utils.start_Activity(MainActivity1.this,com.example.yumengmeng10.ui.activity_login_10.class);
//                    break;
//                    case 11:
//                        Utils.start_Activity(MainActivity1.this,com.example.yumengmeng11.ui.MainActivity_popwindow_11.class);
//                    break;
//
//                }


                                switch (i){
                    case 0:
                        Utils.start_Activity(MainActivity.this,com.example.mylibrarybase.bar.Activity_00_Title1.class,new BasicNameValuePair("pos","1"));
                    break;
                    case 1:
                       Utils.start_Activity(MainActivity.this, activity_01_viewpager.class);
                    break;
                    case 2:
                      Utils.start_Activity(MainActivity.this,Activity_MyRecyclerView_02.class);
                    break;
                    case 3:
                  Utils.start_Activity(MainActivity.this,Bottom_navigation_bar_Activity_03.class);
                    break;
                    case 4:
                      Utils.start_Activity(MainActivity.this,MainActivity_04.class);
                    break;
                    case 5:
                        Utils.start_Activity(MainActivity.this,Main2Activity_05.class);
                    break;
                    case 6:
                        Utils.start_Activity(MainActivity.this,MainActivity_viewpager_list_06.class);
                    break;
                    case 7:
                        Utils.start_Activity(MainActivity.this,MainActivity_list_07.class);
                    break;
                    case 8:
                        Utils.start_Activity(MainActivity.this,MainActivity_dialog_08.class);
                    break;
                    case 9:
                        Utils.start_Activity(MainActivity.this,MainActivity_loadView_09.class);
                    break;
                    case 10:
                        Utils.start_Activity(MainActivity.this,activity_login_10.class);
                    break;
                    case 11:
                        Utils.start_Activity(MainActivity.this,MainActivity_popwindow_11.class);
                    break;
                    case 12:
                        Utils.start_Activity(MainActivity.this,MainActivity_recyclerview_12.class);
                    break;
                    case 13:
                        Utils.start_Activity(MainActivity.this,MainActivity_13_Recyclerviewchebox.class);
                    break;
                    case 14:
                        Utils.start_Activity(MainActivity.this,MainActivity_14_animateLayoutChanges.class);
                    break;
                    case 15:
                        Utils.start_Activity(MainActivity.this,MainActivity_15_flexible.class);
                    break;
                    case 16:
                        Utils.start_Activity(MainActivity.this,MainActivity_16_listmeun.class);
                    break;
                    case 17:
                        Utils.start_Activity(MainActivity.this,MainActivity_ditutu.class);
                    break;
                    case 18:
                        Utils.start_Activity(MainActivity.this,MainActivity_18_AsyncTask.class);
                    break;
                    case 19:
                        Utils.start_Activity(MainActivity.this,MainActivity_19_task_stack.class);
                    break;
                    case 20:
                        Utils.start_Activity(MainActivity.this,MainActivity_20_socket.class);
                    break;
                    case 21:
                        Utils.start_Activity(MainActivity.this,MainActivity_21_handler.class);
                    break;
                    case 22:
                        Utils.start_Activity(MainActivity.this,MainActivity_test.class);
                    break;
                    case 23:
                        Utils.start_Activity(MainActivity.this,PayDemoActivity.class);
                    break;
                    case 24:
                        Utils.start_Activity(MainActivity.this,MainActivity_shijianfenfa_24.class);
                    break;
                    case 25:
                        Utils.start_Activity(MainActivity.this,MainActivity_25_jsonjiamijiemi.class);
                    break;
                    case 26:
                        Utils.start_Activity(MainActivity.this,MainActivity_26.class);
                    break;

                }
            }
        });
    }
    private long mExitTime = -1 ;//双击退出的间隔时间
    //判断 是否 关闭  APP 双击返回键  退出 APP
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if ((System.currentTimeMillis() - mExitTime) > 2000) {
                UtilsToast.showToast(this,"再按一次退出程序" );
               // Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
                mExitTime = System.currentTimeMillis();

            } else {
                finish();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    @Override
    public int getlayouXML() {
        return R.layout.activity_main;
    }

}
